#!/bin/sh


EXECUTABLE=tp1
PLATFORM=0
FLAGSB="-xdb"
FLAGS="$FLAGSB"

if [ ! -f "makefile" ] ; then
	./configure.sh
	
	PLATFORM=$?

	if [ $PLATFORM -lt 100 ] || [ ! -f "makefile" ]; then
		echo
		exit 1
	fi

else
	./platform.sh
	
	PLATFORM=$?

	if [ $PLATFORM -lt 100 ]; then
		echo
		exit 1
	fi

fi

make DEBUG=1


if [ $? -ne 0 ] || [ ! -f "$EXECUTABLE" ]; then
	echo
	echo "Error compiling."
	echo
	exit 2
fi


if [ $PLATFORM -ne 100 ]; then
	FLAGS="$FLAGSB -tui"
fi


echo
echo "Initiating debugging..."
echo

gdb $FLAGS "$EXECUTABLE"


